import pandas as pd
import numpy as np
from sklearn import preprocessing


inputfile = 'data/kaggle_bike_competition_train.csv'
outputfile = 'data/kaggle_bike_processed.csv' #降维后的数据

# 读入数据并处理时间
dataSet = pd.read_csv(inputfile, header = 0) #读入数据
dataSet['month'] = pd.DatetimeIndex(dataSet.datetime).month
dataSet['day'] = pd.DatetimeIndex(dataSet.datetime).dayofweek
dataSet['hour'] = pd.DatetimeIndex(dataSet.datetime).hour

dataSet_origin = dataSet
dataSet = dataSet.drop(['datetime', 'casual', 'registered'], axis=1)
cols = list(dataSet)
cols.append(cols.pop(cols.index('count')))
dataSet = dataSet.ix[:, cols]

# dataSet.to_csv(outputfile,  index=0)

# 正则化数据

print(dataSet.head(1))
data = dataSet
data = data.drop(['count'], axis=1).values
min_max_scaler = preprocessing.MinMaxScaler()
x_minmax = min_max_scaler.fit_transform(data)
dataSet.ix[:, :-1] = x_minmax
dataSet.to_csv("data/kaggle_bike_minmax_scaler.csv", index=0, float_format="%0.4f")